package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.pojo.TRole;
import com.dk.service.RoleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("role")
public class RoleController {

    @Reference //注意一定不要写错, 不然空指针
    private RoleService roleService;

    //跳转查询
    @RequestMapping("toShow")
    public String toShow() {
        return "trole/show";
    }
    //查询
    @RequestMapping("getInfo")
    @ResponseBody
    public List<TRole> getInfo () {
        List<TRole> list = roleService.getInfo();
        return list;
    }
    //跳转新增
    @RequestMapping("toAdd")
    public String toAdd() {
        return "trole/add";
    }
    //增加
    @RequestMapping("addInfo")
    @ResponseBody
    public boolean addInfo(TRole r, @RequestParam("mids") Integer[] mids) {
        return roleService.addInfo(r,mids);
    }
    //修改回显
    @RequestMapping("toUpdate/{rid}")
    public String toUpdate(@PathVariable("rid") Integer rid, Model m) {
        TRole r = roleService.toUpate(rid);
        m.addAttribute("r",r);
        return "trole/update";
    }
    //修改新增
    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(TRole r, @RequestParam("mids") Integer[] mids) {

        return roleService.updateInfo(r,mids);
    }
    //删除
    @RequestMapping("deleteInfo/{rid}")
    @ResponseBody
    public boolean deleteInfo(@PathVariable("rid")Integer rid) {
        return roleService.deleteInfo(rid);
    }
}
